package com.hqyj.controller;

import com.hqyj.pojo.ManagerUserInfo;
import com.hqyj.service.ManagerUserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;

@Controller
@RequestMapping("/manager-user")
public class ManagerUserInfoController {

    @Autowired
    ManagerUserInfoService managerUserInfoService;
    //访问user-list页面
    @RequestMapping("/list")
    public String list(ManagerUserInfo user, ModelMap m){
        //查询分页数据
        HashMap<String, Object> map= managerUserInfoService.select(user);
        //把数据传到前端
        m.put("info",map);
        //把用户输入的查询条件传到前端
        m.put("vv",user.getConValue());

        return "manager-user/user-list";
    }
    //处理表格的ajax数据
    @RequestMapping("/listAjax")
    @ResponseBody
    public HashMap<String,Object> listAjax(ManagerUserInfo user){
        return managerUserInfoService.select(user);
    }


    //打开修改页面
    @RequestMapping("/editPage")
    public String editPage(ManagerUserInfo user, ModelMap m){
        //根据userId查询
        ManagerUserInfo u = managerUserInfoService.selectByUserId(user);
        //把数据传递到前端
        m.addAttribute("user",u);
        return "manager-user/user-edit";

    }
    @RequestMapping("/addPage")
    public String addPage(ManagerUserInfo user, ModelMap m){

        return "manager-user/user-add";
    }
    //处理新建请求
    @RequestMapping("/xinjian")
    @ResponseBody
    public HashMap<String,Object> xinjian(ManagerUserInfo user){

        HashMap<String,Object> map=new HashMap<String, Object>();
        //访问注册方法
        String info = managerUserInfoService.xinjian(user);
        map.put("info",info);

        return  map;
    }




    //处理修改的ajax请求
    @RequestMapping("/edit")
    @ResponseBody
    public HashMap<String,Object> edit(ManagerUserInfo user){
        HashMap<String,Object> map = new HashMap<String,Object>();
        String info = managerUserInfoService.update(user);
        map.put("info",info);
        return map;
    }
    //处理删除的ajax请求
    @RequestMapping("/del")
    @ResponseBody
    public HashMap<String,Object> del(ManagerUserInfo user){
        HashMap<String,Object> map = new HashMap<String,Object>();
        String info = managerUserInfoService.del(user);
        map.put("info",info);
        return map;
    }
}
